//source : https://leetcode.com/problems/two-sum/
//date : 2019-04-14 21:37:53


// Given an array of integers, return indices of the two numbers such that they add up to a specific target.
// You may assume that each input would have exactly one solution, and you may not use the same element twice.
// Example:
// Given nums = [2, 7, 11, 15], target = 9,
// Because nums[0] + nums[1] = 2 + 7 = 9,
// return [0, 1].

#include <iostream>
#include <vector>

using namespace std;

//brute force , time complexity o(n*n) ,space complexity o(1)
/*
class Solution {
public:
    vector<int> twoSum(int* nums,int length,int target){
        cout << "length is : " << length << endl;
        cout << "size of nums : " << sizeof(nums) << endl;
        cout << "size of nums[0]: " << sizeof(nums[0]) << endl;
        vector<int> result;
        for(int i =0;i<length;i++){
            for(int j=0;j<length;j++){
                if((nums[i]+nums[j] == target) && (i != j)){
                    result.push_back(i);
                    result.push_back(j);
                    return result;
                }
            }
        }
        throw "no such two sum";
    }
};

int main(){
    int exNums[4] = {2,4,11,9};
    int exTarget = 9;
    Solution ex;
    try{
        vector<int> exResult = ex.twoSum(exNums,4,exTarget);
        for(int i=0;i<2;i++){
            cout<<exResult[i]<<" ";
        }
    }catch(const char* msg){
        cerr << msg << endl;
    }
    return 0;
}*/

class Solution{
public:
    vector<int> twoSum(vector<int>& nums,int target){
        cout << "length of vector is : " << nums.size() << endl;
        for(int i=0;i<nums.size();i++){
            for(int j=i+1;j<nums.size();j++){
                if(nums[i]+nums[j] == target){
                    vector<int> result = {i,j};
                    return result;
                }
            }
        }
        throw "no such two sum";
    }
};

int main(){
    vector<int> exNums = {2,4,11,9};
    int exTarget = 9;
    Solution ex;
    try{
        vector<int> exResult = ex.twoSum(exNums,exTarget);
        for(int i=0;i<2;i++){
            cout << exResult[i] << " ";
        }
    }catch(const char* msg){
        cerr << msg << endl;
    }
}